package com.dh.blog.task.timer;

import java.util.List;

import javax.annotation.Resource;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.dh.blog.service.BlogService;
import com.dh.blog.vo.BlogVo;
/**
 * 计数器的定时任务
 * @author David
 *
 */
@Component
public class CounterTimer{
	private static final Logger logger = LogManager.getLogger(CounterTimer.class);
	@Resource
	private BlogService blogService;
	@Scheduled(cron="0 0 0 * * ?")//每天午夜时分
	public void flushTotalCount(){
		logger.trace("flushing the counters........");
		List<BlogVo> list = blogService.getBlogList();
		for(int i = 0;i<list.size();i++){
			BlogVo blog = list.get(i);
			blogService.flushCounter(blog.getId());
			logger.trace("finish the flushing for "+blog.getId()+"'s counter");
		}
	}
}
